#include "mloop.h"

void read_pmfscore ()
{
	FILE *fp;

	fp = fopen ("energy.dat", "r");
	if (fp == NULL)
	{
		printf ("open energy.dat failed\n");
		exit (-1);
	}
	fread (pmfscore.energy, sizeof (pmfscore.energy), 1, fp);
	fread (pmfscore.energysol, sizeof (pmfscore.energysol), 1, fp);
	fclose (fp);
}

void calc_pmfscore (struct candidate *p)
{
	int i, j, m;
	float dist;

	p->energypmf = p->energy;
	/*
	p->energypmf = 0.0;

	for (i = loop.start[0]; i <= loop.end[loop.resnum - 1]; i++)
	{
		if (loop.loopatom[i].build_flag == 0)
			continue;
		if (!(loop.loopatom[i].status & IS_CB))
			continue;

		m = 0;
		for (j = 0; j < atomnum; j++)
		{
			if (!(environatom[j].status & IS_CB))
				continue;

			dist = (p->coor[i][0] - environatom[j].coor[0]) * (p->coor[i][0] - environatom[j].coor[0]) + (p->coor[i][1] - environatom[j].coor[1]) * (p->coor[i][1] - environatom[j].coor[1]) + (p->coor[i][2] - environatom[j].coor[2]) * (p->coor[i][2] - environatom[j].coor[2]);

			if (dist < CONTACT_CUTOFF * CONTACT_CUTOFF)
			{
				p->energypmf += pmfscore.energy[loop.loopatom[i].type][environatom[j].type];
				m ++;
			}
		}

		for (j = 0; j < loop.loopnum; j++)
		{
			if (!(loop.loopatom[i].status & IS_CB))
				continue;
			if (loop.loopatom[i].build_flag == 1 && i >= j)
				continue;

			dist = (p->coor[i][0] - p->coor[j][0]) * (p->coor[i][0] - p->coor[j][0]) + (p->coor[i][1] - p->coor[j][1]) * (p->coor[i][1] - p->coor[j][1]) + (p->coor[i][2] - p->coor[j][2]) * (p->coor[i][2] - p->coor[j][2]);

			if (dist < CONTACT_CUTOFF * CONTACT_CUTOFF)
			{
				p->energypmf += pmfscore.energy[loop.loopatom[i].type][loop.loopatom[j].type];
				m ++;
			}
		}

		if (m > END)
			m = END;
		else if (m < START)
			m = START;
		p->energypmf += pmfscore.energysol[loop.loopatom[i].type][m - START];
	}
	*/
}
